#include "EventActor.H"
#include "Event.H"

void EventActor::Notify( Event *e )
{
    ::pthread_mutex_lock( &mQueueMutex );
    std::cout << " EventPushed " << std::endl;
    mEventQueue.push_back(e);
    ::pthread_cond_signal ( &mQueueCond );
    ::pthread_mutex_unlock( &mQueueMutex );
}

void EventActor::Run()
{
    for (;;)
    {
        WaitForEvent();
        ProcessEventQueue();
        ReadyForNextEvent();
    }
}
void EventActor::ReadyForNextEvent()
{
    pthread_mutex_unlock( &mQueueMutex );
}

void EventActor::WaitForEvent()
{
    ::pthread_mutex_lock( &mQueueMutex );
    while ( mEventQueue.size() == 0 )
    {
        ::pthread_cond_wait(&mQueueCond, &mQueueMutex);
    }
}
